﻿@using QDT.Common
@using QDT.Core
@using QDT.Core.Assignments
@using QDT.Core.Projects
@model QDT.Core.Assignments.Assignment
@{
    ViewBag.Title = "标的详情";
    Project project = Html.F().GetProject(Model.ProjectId);
    var days = (project.RepayEndTime.Value.Date - DateTime.Now.Date).Days;
}   
      
@section Head
{
    <script type="text/javascript" src="@Url.Content("~/Content/Default/JS/vendor/modernizr-2.8.0.min.js")"> </script>
    <script type="text/javascript" src="@Url.Content("~/Content/Default/JS/vendor/raphael.2.1.0.min.js")"> </script>
    <script type="text/javascript" src="@Url.Content("~/Content/Default/JS/vendor/justgage.1.0.1.min.js")"> </script>
}

<div class="ui-body">
    <div class="ui-inner">

        <div class="ui-box fn-clear">
            
            <div class="ui-box-mian">
                <div class="ui-box-hd">
                    <h1 class="ui-box-title">债权转让项目 EAD<span>@Model.ID.ToString("0000")</span></h1>
                </div>
                <table class="ui-project-detail">
                    <tr>
                        <td class="title">原始项目：</td>
                        <td><a href="@Url.Action("Index", "Project", new {id = project.ID})">@project.Name</a></td>
                        <td class="title">原债权人：</td>
                        <td>@(Html.F().GetUserName(Model.UserId).ToConfuse(1, 1, 3))</td>
                    </tr>
                    <tr>
                        <td class="title">债权总价：</td>
                        <td style="color: #f39c12;">@Model.Money.ToMoney()</td>
                        <td class="title">转让价格：</td>
                        <td>@Model.BuyAmount.ToMoney()</td>
                    </tr>
                    <tr>
                        <td class="title">原标年化：</td>
                        <td>@project.Rate<span>%</span></td>
                        <td class="title">到期日期：</td>
                        <td>@((project.RepayEndTime.Value).ToString("yyyy年MM月dd日"))</td>
                    </tr>
                    <tr>
                        <td class="title">剩余时间：</td>
                        <td>@(days<0 ? 0: days)<span>天</span></td>
                        <td class="title">折让率：</td>
                        <td>@Model.DiscountRate<span>%</span></td>
                    </tr>
                    <tr>
                        <td class="title">还款方式：</td>
                        <td>付息还本</td>
                        <td class="title">保障方式：</td>
                        <td>本金 + 利息</td>
                    </tr>
                </table>
            </div>
            
            <div class="ui-box-side">
                <div id="project_progress" class="ui-project-rate"></div>
                <div class="ui-project-pay">
                    <dl class="fn-clear">
                        <dt>可投金额：</dt>
                        <dd class="big">@Model.NeedMoney.ToMoney()</dd>
                    </dl>
                    
                    @Html.Action("UserBalance", "Project")

                    @if (Model.Status == AssignmentStatus.Progress)
                    {
                        <div id="bid_form">
                            <form action="javascript:;" method="post">
                                <p>
                                    <input class="ui-input ui-input-large" name="money" type="text"/>
                                </p>
                                <p>
                                    <a href="javascript:;" id="bid_preview_btn" onclick="bidpreview()" class="ui-btn-big">投资</a>
                                </p>
                            </form>
                        </div>
                    }
                    else
                    {
                        <p>
                            <button class="ui-btn-big" style="background: #bdc3c7;">
                                @switch (Model.Status)
                                {
                                    case AssignmentStatus.Completed:
                                        <span>已满</span>
                                        break;
                                    case AssignmentStatus.Cancel:
                                        <span>已结束</span>
                                        break;
                                }
                            </button>
                        </p>
                    }

                    <p class="small">
                        @if (Model.Status != AssignmentStatus.Progress)
                        {
                            <span>剩余时间：0天0时0分</span>
                        }
                        else
                        {
                            <span>剩余时间：@Model.EndTime.RemainTime()</span>
                        }
                    </p>
                        
                </div>
            </div>

        </div>
        <div class="ui-grid-row">
            <div class="ui-grid-13">
            @Html.Action("RepayList", "Project", new { projectid = Model.ProjectId })
            </div>
            <div id="assign_bid_list">
            @Html.Action("BidList", new { assignid = Model.ID })
            </div>
        </div>
    </div>
</div>

<div class="ui-layer" id="dialog_assignbid_preview">
    <div class="lymask">
    </div>
    <table class="lytable">
        <tbody>
            <tr>
                <td class="lytd">
                    <div class="lywrap">
                        <div class="lytt">
                            <h2 class="u-tt">购买债权</h2>
                            <a href="javascript:void(0)" onclick=" closeBid() ">
                                <span class="lyclose">×</span>
                            </a>
                        </div>
                        <div class="lyct" id="assignbid_form_preview">
                            
                        </div>
                        <div class="lybt">
                            <div class="lybtns">
                                <button type="button" id="submit_assignbid_button" onclick="submit_bid()" class="ui-button ui-button-red big">确认购买</button>
                            </div>
                        </div>
                    </div>
                </td>
            </tr>
        </tbody>
    </table>
</div>

<script type="text/javascript">
    
    function bidpreview() {
        var money = $('input[name="money"]').val();
        if (money == "" || money == undefined) {
            alert('请输入购买金额！');
            return;
        }
        var url = '@Url.Action("BidPreview", "Assignment")' + '?id=@Model.ID&money=' + money;

        $('#dialog_assignbid_preview #assignbid_form_preview').load(url);

        $('#dialog_assignbid_preview').addClass("ui-layer-show");

        $.ajax({
            url: url,
            type: 'POST',
            dataType: "json",
            success: function (obj) {
                if (obj.Status == true) {
                    $('#dialog_assignbid_preview #assignbid_form_preview').html(obj.Data);
                } else {
                    $('#dialog_assignbid_preview #assignbid_form_preview').html(obj.Info);
                }
            }
        });
    }

    function closeBid() {
        $('#dialog_assignbid_preview').removeClass("ui-layer-show");
    }

    $('#submit_assignbid_button').click(function() {
        $('#dialog_assignbid_preview').removeClass("ui-layer-show");
        $('#submit_assignbid_form').submit();
    });

    $("#project_progress").ready(function() {
        var progress = new JustGage({
            id: "project_progress",
            value: @Model.Progress.ToString("0.0"),
            min: 0,
            max: 100,
            title: "@(Model.Progress >= 100 ? "融资成功" : "投资进度")",
            label: "",
            showInnerShadow: false,
            levelColors: [
                "#2ecc71",
                "#f1c40f",
                "#e74c3c"
            ],
            gaugeWidthScale: 1
        });
    });


    $('#more_bid_list').click(function() {
        $("#assign_bid_list").load("/Assignment/AllBidList?assignid=" + @Model.ID);
    });

</script>
